package tgc.edu.exam.entity;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Transient;

import org.springframework.data.annotation.CreatedBy;

import com.fasterxml.jackson.annotation.JsonIgnore;

import tgc.edu.exam.custom.BaseEntity;

@Entity
public class SysDept extends BaseEntity<UUID> {
	private String name;   //部门名称
	@JsonIgnore
	private SysDept parent;   //上级
	@JsonIgnore
	private List<SysDept> children = new ArrayList<>();	//下级
	private Integer idx1;  //排序
	
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	@ManyToOne
	@CreatedBy
	public SysDept getParent() {
		return parent;
	}
	public void setParent(SysDept parent) {
		this.parent = parent;
	}
	@OneToMany(cascade = CascadeType.ALL, mappedBy="parent")
	@OrderBy(value="idx1")
	public List<SysDept> getChildren() {
		return children;
	}
	public void setChildren(List<SysDept> children) {
		this.children = children;
	}
	public Integer getIdx1() {
		return idx1;
	}
	public void setIdx1(Integer idx1) {
		this.idx1 = idx1;
	}
	
	@Transient
	public UUID getParentId() {
		return parent==null?null:parent.getId();
	}
}
